package crm.model.teacherPC.net;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import crm.model.NetConst;


public class PcWindow implements Serializable{
	ObjectInputStream is; ObjectOutputStream os;
	int index;
	String name = "";
	public PcWindow(int index, ObjectInputStream is, ObjectOutputStream os){
		this.index=index;
		this.is=is;
		this.os=os;

	}
	private String refreshName(){
		try {
			os.writeObject(NetConst.WINDOWDATA);
			os.writeObject(new Integer[]{index, NetConst.WNAME});
			String s = (String) is.readObject();
			name = s;
			return s;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	public void init() {
		refreshName();
	}
	public void minimize(){
		try {
			os.writeObject(NetConst.WINDOWDATA);
			os.writeObject(new Integer[]{index, NetConst.WMIN});
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void maximize(){
		try {
			os.writeObject(NetConst.WINDOWDATA);
			os.writeObject(new Integer[]{index, NetConst.WMAX});
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void kill(){
		try {
			os.writeObject(NetConst.WINDOWDATA);
			os.writeObject(new Integer[]{index, NetConst.WKILL});

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


	public String toString() {

		return name;
	}

	public boolean equals(Object o) {
		if (o instanceof PcWindow){
			PcWindow win = (PcWindow)o;
			return win.name.equals(name);
		}
		// TODO Auto-generated method stub
		return super.equals(o);
	}
	public String getName(){
		return name;
	}
}
